package com.badibadi.activity;

import com.badibadi.activity.BaseActivity.ViewFragmentHolder;
import com.badibadi.fragment.ClubOverview0Fragmente;
import com.badibadi.fragment.MyClubFragment0;
import com.badibadi.fragment.MyClubFragment0.getFragmentData;
import com.badibadi.fragment.MyClubFragment1;
import com.badibadi.fragment.MyClubFragment2;
import com.badibadi.fragment.RecordFragment1;
import com.badibadi.fragment.RecordFragment2;
import com.badibadi.infos.ClueTypeModel;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.TabHostUtils;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.drawable;
import com.badibadi.uniclubber.R.id;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.string;
import com.libjph.util.StringUtil;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TabHost;
import android.widget.TextView;

/**
 * 我的俱乐部 2014-8-27
 * 
 * @author Administrator
 * 
 */
public class ClubMyClubActivity extends BaseActivity {
	private TabHost mTabHost;
	/**
	 * tabHost的点击项
	 */
	private int TabHostItem = 0;
	private FragmentManager manager;
	private MyClubFragment0 fragmente0;
	// private MyClubFragment1 fragmente1;
	// private MyClubFragment2 fragmente2;
	private int add_in;
	// private PopupWindow popup = null;
	private Bundle bun = null;
	private ClueTypeModel clubTypeModel;
	// 文本框
	// private AutoCompleteTextView index_autocomplete_txt_view;
	public String uid = "1";
	public String fid = "-1";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);// my_record_layout
		goToTheTitle();
		setContentView(R.layout.club_myclub);
		manager = getSupportFragmentManager();
		uid = Utils.getUid(ClubMyClubActivity.this);
		fid = getIntent().getStringExtra("fid");
		if (fid == null) {
			fid = "-1";
		}
		initid();
		init();
		initTabHost(R.string.Create);
	}

	protected void initid() {

	}

	private void init() {

		/**
		 * IntexActivity(IndexClub0Fragment)中传过来的种类，还需要做修改（该隐藏的隐藏）
		 */
		clubTypeModel = (ClueTypeModel) getIntent().getSerializableExtra(
				"ClubListActivity");
		if (clubTypeModel != null) {
			if (!StringUtil.isNullOrEmpty(clubTypeModel.getName())) {
				((TextView) (this.findViewById(R.id.title))).setText(""
						+ clubTypeModel.getName());
			}
		}
		LoadingFragment(0, uid, fid);
		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						fragmente0.getSearchIsReturnUp(new getFragmentData() {

							@Override
							public void getIsReturnUp(boolean isReturn) {

							}
						});
					}
				});
		this.findViewById(R.id.add_Club).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						Constants.is_shuaxin = true;
						Intent intent = new Intent(ClubMyClubActivity.this,
								CreationNewClubActivity.class);
						startActivity(intent);
						overridePendingTransition(R.anim.slide_left,
								R.anim.slide_right);
					}
				});
	}

	protected void initTabHost(int stringTab3) {
		mTabHost = (TabHost) findViewById(R.id.club_list_tabhost);
		mTabHost.setup();
		mTabHost.addTab(mTabHost
				.newTabSpec("club_list one")
				.setIndicator(getResources().getString(R.string.Newest),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		mTabHost.addTab(mTabHost
				.newTabSpec("club_list two")
				.setIndicator(getResources().getString(R.string.Hottest),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		mTabHost.addTab(mTabHost
				.newTabSpec("club_list three")
				.setIndicator(getResources().getString(stringTab3),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		TabHostUtils.SetTabHost(this, mTabHost);
		mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {
				// Toast.makeText(getApplicationContext(),
				// "" + mTabHost.getCurrentTab(), 0).show();
				switch (mTabHost.getCurrentTab()) {
				case 0:
					LoadingFragment(0, uid, fid);
					break;
				case 1:
					LoadingFragment(1, uid, fid);
					break;
				case 2:
					LoadingFragment(2, uid, fid);
					break;
				default:
					LoadingFragment(0, uid, fid);
					break;
				}
			}
		});
	}

	/**
	 * 根据num来读取framgent
	 * 
	 * @param num
	 */
	protected void LoadingFragment(int num, String uid, String fid) {
		FragmentTransaction transaction = manager.beginTransaction();
		fragmente0 = MyClubFragment0.getInstance();
		Bundle bun = new Bundle();
		switch (num) {
		case 0:
			bun.putString("uid", uid);
			bun.putString("fid", fid);
			bun.putString("type", "0");
			fragmente0.setArguments(bun);
			transaction.replace(R.id.club_overview_layout, fragmente0);
			transaction.commit();
			break;
		case 1:
			bun.putString("uid", uid);
			bun.putString("fid", fid);
			bun.putString("type", "1");
			fragmente0.setArguments(bun);
			transaction.replace(R.id.club_overview_layout, fragmente0);
			transaction.commit();
			break;
		case 2:
			bun.putString("uid", uid);
			bun.putString("fid", fid);
			bun.putString("type", "2");
			fragmente0.setArguments(bun);
			transaction.replace(R.id.club_overview_layout, fragmente0);
			transaction.commit();
			break;
		}

	}
}
